import service
import blue
import uthread
import uix
import uiutil
import xtriui
import form
import util
import types
import triui
import log

class Focus(service.Service):
    __guid__ = 'svc.focus'
    __servicename__ = 'focus'
    __displayname__ = 'Focus Tool'
    __dependencies__ = []

    def Run(self, memStream = None):
        self.wr = util.WeakRefAttrObject()



    def SetChannelFocus(self, char = None):
        channel = self.GetFocusChannel()
        if (channel is not None):
            channel.Maximize()
            stack = getattr(channel.sr, 'stack', None)
            if (stack and (stack.state == uix.UI_HIDDEN)):
                return 
            channel.SetCharFocus(char)



    def SetFocusChannel(self, channel = None):
        if (channel is not None):
            self.wr.focusChannelWindow = channel
        else:
            delattr(self.wr, 'focusChannelWindow')



    def GetFocusChannel(self):
        focus = getattr(self.wr, 'focusChannelWindow', None)
        if (focus and (not focus.destroyed)):
            return focus




